/*
 * TitleItem.cpp
 *
 *  Created on: 2011-1-14
 *      Author: Administrator
 */

#include "TitleItem.h"
#include "ListBox.h"

CTitleItem* CTitleItem::NewL(const CListBox* aOwner)
	{
	CTitleItem* self = CTitleItem::NewLC(aOwner);
    CleanupStack::Pop(self);
    return self;
	}

CTitleItem* CTitleItem::NewLC(const CListBox* aOwner)
	{
	CTitleItem* self = new(ELeave) CTitleItem();
    CleanupStack::PushL(self);
    self->ConstructL(aOwner);
    return self;
	}

CTitleItem::CTitleItem()
	{
	
	}

CTitleItem::~CTitleItem()
	{

	}

void CTitleItem::ConstructL(const CListBox* aOwner)
	{
	iOwner = aOwner;
	ActivateL();
	}

void CTitleItem::Draw(CWindowGc& gc, const TRect& aRect) const
	{
	CBaseControl::Draw(gc, aRect);
	TPoint position = Position();
    if (iTitle)
    	{
    	gc.UseFont(iTitleFont);
    	gc.SetPenColor(iTitleColor);
    	TRect titleRect(iTitlePosition, TPoint(Rect().iBr.iX - 2, iTitlePosition.iY + iTitleFont->HeightInPixels() + 4));
    	titleRect.Move(position);
    	TInt baseline = titleRect.Height() / 2 + iTitleFont->AscentInPixels() / 2;
    	gc.DrawText(*iTitle, titleRect, baseline, CGraphicsContext::ECenter, 0);
    	gc.DiscardFont();
    	}
    if (iOwner && iOwner->DrawLine())
    	{
		TInt gap = 0;
		if (iOwner->ScrollBar() && iOwner->ScrollBar()->Visible())
			gap = 6;
		CGraphicsTool::DrawLine(gc,TPoint(aRect.iTl.iX,aRect.iBr.iY - 1),TPoint(aRect.iBr.iX - gap,aRect.iBr.iY - 1),KRgbWhite);
    	}
	}

void CTitleItem::DrawFocusEffect(CWindowGc& /*gc*/, const TRect& /*aRect*/) const
	{
	}

void CTitleItem::DrawLostFocusEffect(CWindowGc& /*gc*/, const TRect& /*aRect*/) const
	{
	}
